package data.database;

import java.io.IOException;

import exception.ImageNotFoundException;
import exception.VideoNotFoundException;

import video.local.analyse.Video;

public class Raw2Stereo {
	private DatabaseConnection dc;
	
	public Raw2Stereo(DatabaseConnection dc){
		this.dc = dc;
	}
	
	/**
	 * check record in raw table, if qualified, then dump into stereo table.
	 * @param rawTableName
	 * @param stereoTableName
	 */
	public void dump(String rawTableName, String stereoTableName){
		RawTable rt = new RawTable(dc, rawTableName);
		StereoTable st = new StereoTable(dc, stereoTableName);
		VideoRecord vr = rt.getOneCheckRecord();	//start record
		
		while( null != vr){	
			try {
				Video v = new Video(vr);
				if( v.isStereo() ){
					System.out.println(vr.id+" is stereo.");
					st.addData(vr);
				}else
					System.out.println(vr.id+" is not stereo.");
				rt.setChecked(vr.id);
			} catch (VideoNotFoundException e) {	//video not down loaded
				System.out.println(vr.id+"\tVideo file not found.");
				rt.setDownloadFalse(vr.id);
			} catch (ImageNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			vr = rt.getOneCheckRecord();	//next record
		}
		
	}
}
